<template>
	<!-- 供应商管理 -->
	<view>
		<view class="toptext">
			<text class="text">{{title}}</text>
			<image v-show="show" @click="delect(list.id)" class="img1" src="../../../static/paimg/删除.png"></image>
		</view>
		<view class="item">
			<text class="text">供应商名称:</text>
			<input type="text" disabled=false class="text1" v-model="list.name">
		</view>
		<view class="item">
			<text class="text">供应商编号:</text>
			<input type="text" disabled=false class="text1" v-model="list.id">
		</view>
		<view class="item">
			<text class="text">联系人名称:</text>
			<input type="text" :disabled="dis" class="text1" v-model="list.linl_name">
		</view>
		<view class="item">
			<text class="text">供应商电话:</text>
			<input type="text" :disabled="dis" class="text1" v-model="list.tel">
		</view>
		<view class="item">
			<text class="text">供应商所在:</text>
			<input type="text" :disabled="dis" class="text1" v-model="list.address">
		</view>
		<view class="item">
			<text class="text">供应商邮箱:</text>
			<input type="text" :disabled="dis" class="text1" v-model="list.email">
		</view>
		<view class="item">
			<text class="text">公司所在地:</text>
			<input type="text" :disabled="dis" class="text1" v-model="list.company_location">
		</view>
		<view class="item">
			<text class="text">开户银行名称:</text>
			<input type="text" :disabled="dis" class="text2" v-model="list.bank_name">
		</view>
		<view class="item">
			<text class="text">开户银行账号:</text>
			<input type="text" :disabled="dis" class="text2" v-model="list.bank_account">
		</view>
		<view  v-show="show" class="btnbox">
			<button @click="updata">{{btnname}}</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title:'供应商管理',dis:'false',btnname:'更新供应商信息',type:true,show:true
			}
		},
		onLoad(option){
			if(option.type !== undefined){
				this.show = false;
			}
			var opt = JSON.parse(option.item)
			this.list = opt;
		},
		methods: {
			async updata(){
				//成员id
				this.type = !this.type;
				if(this.type==true){
					// 第二次点击
					this.type =  true;
					this.flag=0;
					const res = await this.Request({
						url:'api/supplie/upsupdata',
						method:'PUT',
						data:{linl_name:this.list.linl_name,tel:this.list.tel,
						address:this.list.address,email:this.list.email,bank_name:this.list.bank_name,
						bank_account:this.list.bank_account,company_location:this.list.company_location,id:this.list.id,}
					})
					if(res.data.affectedRows = 1){
						uni.showToast({
							title: '更新成功'
						})
						setTimeout(() => {
							uni.navigateBack({
								delta:2
							})
						},500)
					}
				}else{
					// 第一次点击
					this.type =  false;
					this.dis = false;
					this.btnname = "保存"
				}
			},
			delect(e){
				uni.showModal({
					title: '提示',
					content: '是否确认删除此供应商',
					success(res) {
						if (res.confirm) {
							uni.request({
								url:'api/supplie/supdelect',
								method:'DELETE',
								data:{id:e},
								success(res){
									setTimeout( () => {
										uni.showToast({
											title: '删除成功',
										})
									},300)
									uni.reLaunch({
										url:'/pages/public/supplie/supment',
									})
								}
							})
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.toptext{
		width: 100%;
		background-color: #efefef;
		display: flex;
		border-bottom: 1px solid #ccc;
		.text{
			margin: 5px 0 5px 5px;
			font-size: 110%;
			font-weight: 700;
			color: #d3d3d3;
		}
		.img1{
			margin: auto 0;
			height: 20px;
			width: 20px;
			margin-left: 260px;
		}
	}
	.item{
		display: flex;
		height: 60px;
		margin: 5px;
		border-top: 1.5px solid #d3d3d3;
		border-bottom: 1.5px solid #d3d3d3;
		border-radius: 10px;
		.text{
			margin:auto 0;
			font-size: 16px;
			font-weight: 600;
		}
		.text1{
			margin:auto 0;
			margin-left: 46px;
		}
		.text2{
			margin:auto 0;
			margin-left: 30px;
		}
	}
	.btnbox{
		button{
			width: 60%;
			margin-left: 20%;
			margin-top: 10px;
			margin-bottom: 100px;
		}
	}
</style>
